


#include <iostream>
#include <unistd.h>

#include "vlc/vlc.h"
#include "vlc/libvlc_media.h"

using namespace std;

int main()
{
    libvlc_instance_t *vlcInstance;
    libvlc_media_player_t *mediaPlayer;
    libvlc_media_t *media;


    std::cout << "VLC VERSION: " << libvlc_get_version() << std::endl;
    // 等待 1 秒
    int waitTime = 3;

    /*
     *  libvlc_instance_t *vlc_ins;
        const char *vlc_args[] =
        {
            "--ignore-config",
            "--network-caching=500",
            "--rtsp-tcp",
            "--longhelp",
            "--advanced",
        };
        vlc_ins = libvlc_new(sizeof(vlc_args)/sizeof(vlc_args[0]), vlc_args);

     *
     * */
    // 创建并初始化 libvlc 实例
    const char *vlc_args[] =
            {
                    "--ignore-config"
                    ,"--network-caching=500"
                    ,"--rtsp-tcp"
//                    ,"    --playlist-skip-ads rtsp://182.145.195.237:8099/DevAor=51000000001317000031"
//                    "--longhelp",
//                    "--advanced",
                    ,"--vout=vdummy"            // 不产生播放窗口
                    ,"--no-osd"                 // 不显示字幕
                    ,"--no-snapshot-preview"    // 不做截图预览

            };
    vlcInstance = libvlc_new(sizeof(vlc_args)/sizeof(vlc_args[0]), vlc_args);
//    vlcInstance = libvlc_new(0, NULL);

    // 创建一个 media，参数是一个媒体资源位置（例如：有效的 URL）。
    media = libvlc_media_new_location(vlcInstance, "rtsp://182.145.195.237:8099/DevAor=51000000001317000031");

    // 不使用硬解码
//    libvlc_media_add_option(media, ":avcodec -hw=none");

    //创建一个 media player 播放环境
    mediaPlayer = libvlc_media_player_new_from_media(media);

    // 现在，不需要保留 media 了
    libvlc_media_release(media);

    //播放 media player
    libvlc_media_player_play(mediaPlayer);

    //让它播放一会
    sleep(waitTime);
    std::cout << "DOING CAPTURE" << std::endl;
    //截图
    libvlc_video_take_snapshot(mediaPlayer, 0, "test.jpg", 0, 0);

    sleep(waitTime);

    //停止播放
    libvlc_media_player_stop(mediaPlayer);

    //释放 media player
    libvlc_media_player_release(mediaPlayer);

    // 释放 libvlc 实例
    libvlc_release(vlcInstance);

    return 0;
}